<?php
/**
 * Created by PhpStorm.
 * User: Windows
 * Date: 2017/4/25
 * Time: 15:44
 */
namespace Task;

use \Workerman\Worker;

class TaskWorker extends Worker{

    public function __construct($socket_name)
    {
        parent::__construct($socket_name);
        $this->onWorkerStart = array($this, 'onStart');
        $this->onMessage = array($this, 'onMessage');
        $this->onWorkerStop = array($this, 'onStop');
    }

    public function onStart(){
        echo 'start....'."\n";
    }

    public function onMessage($connection,$data){

        $task_data = json_decode($data, true);
        var_dump($task_data);
        echo 'udp success'."\n";
        // 发送结果
        $connection->send(json_encode($task_data));

    }

    public function onStop(){
        echo 'stop...'."\n";
    }
}